package com.mingtu.jgspatrol.adapter;

import android.content.Context;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.common.base.BaseApplication;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.bean.IndexNewsBean;

public class IndexNewsAdapter extends BaseQuickAdapter<IndexNewsBean.DataBean, BaseViewHolder> {
    private Context context;

    public IndexNewsAdapter(Context context) {
        super(R.layout.item_exchange);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, IndexNewsBean.DataBean listBean) {
        String imgUrl = listBean.getContentImg();
        String title = listBean.getContentTitle();
        String time = listBean.getCreateTime();

        if (!StringUtils.isEmpty(imgUrl)) {
            Glide.with(context)
                    .load(imgUrl)
                    .apply(BaseApplication.getRequestOptions())
                    .into((ImageView) helper.getView(R.id.iv_img));
        } else {
            helper.getView(R.id.iv_img).setBackgroundResource(R.mipmap.img_default_news);
        }

        if (!StringUtils.isEmpty(title)) {
            helper.setText(R.id.tv_title, title);
        } else {
            helper.setText(R.id.tv_title, "");
        }

        if (!StringUtils.isEmpty(time)) {
            helper.setText(R.id.tv_time, time);
        } else {
            helper.setText(R.id.tv_time, "");
        }
    }

}
